<template>
  <div>
    <en-table-layout :tableData="tableData.data" :loading="loading" :selectionChange="selectionChange">
      <div slot="toolbar" class="inner-toolbar">
        <div class="toolbar-btns">
          <el-button size="mini" type="primary" @click="openDeliverGoodsialog">订单发货</el-button>
          <el-button size="mini" type="primary" @click="importExcel">批量导入发货</el-button>
          <el-button size="mini" type="primary" @click="cancelOrder">批量取消订单</el-button>
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-download"
            @click="handleExportOrderItems"
          >导出订单明细</el-button>
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-download"
            @click="handleExportOrders"
          >导出Excel</el-button>
          <span class="exprot-tip">导出时，会按右侧高级搜索中的筛选条件导出全部数据。</span>
        </div>
        <div class="toolbar-search">
          <en-table-search
            @search="searchEvent"
            @advancedSearch="advancedSearchEvent"
            advanced
            advancedWidth="465"
            placeholder="请输入订单编号">
            <template slot="advanced-content">
              <el-form ref="advancedForm" :model="advancedForm" label-width="70px">
                <el-form-item label="商品名称" class="toolbar-input">
                  <el-input v-model="advancedForm.goods_name" clearable></el-input>
                </el-form-item>
                <el-row :gutter="10">
                  <el-col :span="12">
                    <el-form-item label="会员名称" class="toolbar-input" prop="ship_name">
                      <el-input v-model="advancedForm.nick_name" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="店铺名称" class="toolbar-input">
                      <en-shop-picker @changed="(shop) => { advancedForm.seller_id = shop.shop_id }"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="下单时间" class="toolbar-input">
                  <el-date-picker
                    v-model="advancedForm.order_time_range"
                    type="datetimerange"
                    align="center"
                    :editable="false"
                    unlink-panels
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="timestamp"
                    :picker-options="{ shortcuts: MixinPickerShortcuts }"
                    :default-time="['00:00:00', '23:59:59']"
                  ></el-date-picker>
                </el-form-item>
                <el-row :gutter="10">
                  <el-col :span="12">
                    <el-form-item label="收货人" class="toolbar-input">
                      <el-input v-model="advancedForm.ship_name" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="收货电话" class="toolbar-input">
                      <el-input v-model="advancedForm.ship_mobile" clearable></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :span="12">
                    <el-form-item label="团长姓名" class="toolbar-input">
                      <el-input v-model="advancedForm.lv1_member_nick_name" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="团长电话" class="toolbar-input">
                      <el-input v-model="advancedForm.lv1_member_mobile" clearable></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :span="12">
                    <el-form-item label="订单状态" class="toolbar-input">
                      <el-select v-model="advancedForm.order_status" placeholder="请选择" clearable>
                        <el-option label="新订单" value="NEW" />
                        <el-option label="已确认" value="CONFIRM" />
                        <el-option label="已付款" value="PAID_OFF" />
                        <el-option label="已发货" value="SHIPPED" />
                        <el-option label="已收货" value="ROG" />
                        <el-option label="已完成" value="COMPLETE" />
                        <el-option label="已取消" value="CANCELLED" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="支付方式" class="toolbar-input">
                      <el-select v-model="advancedForm.payment_type" placeholder="请选择" clearable>
                        <el-option label="在线支付" value="ONLINE" />
                        <el-option label="货到付款" value="COD" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="10">
                  <el-col :span="12">
                    <el-form-item label="订单来源" class="toolbar-input">
                      <el-select v-model="advancedForm.client_type" placeholder="请选择" clearable>
                        <el-option label="PC" value="PC" />
                        <el-option label="WAP" value="WAP" />
                        <el-option label="NATIVE" value="NATIVE" />
                        <el-option label="REACT" value="REACT" />
                        <el-option label="MINI" value="MINI" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="订单类型" class="toolbar-input">
                      <el-select v-model="advancedForm.order_type" placeholder="请选择" clearable>
                        <el-option label="普通订单" value="normal" />
                        <el-option label="拼团订单" value="pintuan" />
                        <el-option label="社区团购订单" value="shetuan" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </template>
          </en-table-search>
        </div>
      </div>
      <template slot="table-columns">
        <!--订单编号-->
        <el-table-column type="selection" width="50" fixed/>
        <!--订单编号-->
        <el-table-column prop="sn" label="订单编号" min-width="116" />
        <!--下单时间-->
        <el-table-column prop="create_time" :formatter="MixinUnixToDate" label="下单时间" min-width="120" />
        <!--订单总额-->
        <el-table-column label="订单总额" min-width="70">
          <template slot-scope="scope">{{ scope.row.order_price | unitPrice('￥') }}</template>
        </el-table-column>
        <!--店铺名称-->
        <el-table-column prop="seller_name" label="店铺名称" min-width="80" />
        <el-table-column label="团长姓名" min-width="80">
          <template slot-scope="scope">{{ scope.row.lv1_member_nick_name}}</template>
        </el-table-column>
        <el-table-column label="团长电话" min-width="86">
          <template slot-scope="scope">{{ scope.row.lv1_member_mobile}}</template>
        </el-table-column>
        <!--收货人-->
        <el-table-column prop="ship_name" label="收货人" min-width="80" />
        <el-table-column prop="ship_mobile" label="收货人电话" min-width="86" />
        <!--订单状态-->
        <el-table-column prop="order_status" label="订单状态" min-width="72">
          <template slot-scope="{ row }">
            <span>{{ row.order_status === 'NEW' ?
                '新订单' : row.order_status === 'INTODB_ERROR' ?
                '出库失败' : row.order_status === 'CONFIRM' ?
                '已确认' : row.order_status === 'PAID_OFF' ?
                '已付款' : row.order_status === 'FORMED' ?
                '已成团' : row.order_status === 'SHIPPED' ?
                '已发货' : row.order_status === 'ROG' ?
                '已收货' : row.order_status === 'COMPLETE' ?
                '已完成' : row.order_status === 'CANCELLED' ?
                '已取消' : row.order_status === 'AFTER_SERVICE' ?
                '售后中' : ''}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="order_type" label="订单类型" min-width="68">
          <template
            slot-scope="scope"
          >{{ scope.row.order_type === 'shetuan'? '社团': scope.row.order_type === 'pintuan'? '拼团订单': scope.row.order_type === 'normal'? '普通订单':'' }}</template>
        </el-table-column>
        <!--付款状态-->
        <el-table-column prop="pay_status" label="付款状态" min-width="72" >
          <template slot-scope="{ row }">
            <span> {{ row.pay_status === 'PAY_NO' ? '新订单' : row.pay_status === 'PAY_PARTIAL' ? '部分支付' : '已付款' }} </span>
          </template>
        </el-table-column>
        <!--发货状态-->
        <el-table-column prop="ship_status" label="发货状态" min-width="72" >
          <template slot-scope=" { row }">
            <span>{{ row.ship_status === 'SHIP_NO' ? '未发货' : row.ship_status === 'SHIP_YES' ? '已发货' : '已收货'}}</span>
          </template>
        </el-table-column>
        <!--支付方式-->
        <el-table-column label="支付方式" min-width="68">
          <template slot-scope="scope">{{ scope.row.payment_type | paymentTypeFilter }}</template>
        </el-table-column>
        <!--订单来源-->
        <el-table-column prop="client_type" label="订单来源" min-width="68" />
        <!--操作-->
        <el-table-column label="操作" width="80">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.order_status !== 'COMPLETE'"
              size="mini"
              type="primary"
              @click="handleOperateOrder(scope.$index, scope.row)"
            >操作</el-button>
            <el-button v-else size="mini" @click="handleOperateOrder(scope.$index, scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </template>
      <el-pagination
        v-if="tableData"
        slot="pagination"
        @size-change="handlePageSizeChange"
        @current-change="handlePageCurrentChange"
        :current-page="tableData.page_no"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="tableData.page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.data_total"
      ></el-pagination>
    </en-table-layout>
    <!-- 批量导入 -->
    <el-dialog title="导入Excel" width="400px" :visible.sync="importDialog">
      <el-form
        ref="importForm"
        label-width="100px"
        size="small"
        :model="importForm"
        :rules="importFormRules"
        >
        <el-form-item prop="uploadFile" label-width="0">
          <div class="upload">
            <el-button size="small" type="primary">
              <a href="https://egale-shop.oss-cn-hangzhou.aliyuncs.com/excel/%E8%AE%A2%E5%8D%95%E6%95%B4%E5%8D%95%E6%89%B9%E9%87%8F%E5%8F%91%E8%B4%A7%E6%A8%A1%E6%9D%BF.xlsx">下载模板</a>
            </el-button>
            <div class="el-upload__tip" slot="tip">只能上传 .xlsx, .xls文件</div>
              <el-upload
                v-model="importForm.uploadFile"
                :limit="1"
                drag
                ref="upload"
                action="#"
                :http-request="excelLoadShow"
                :on-change="onUploadChange"
                >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
              </el-upload>
            </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary"  @click="submitFileForm('importForm')">确 定</el-button>
        <el-button size="small" @click="handleCancel('importForm')">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 发货确认 -->
    <el-dialog :visible.sync="deliverGoodsDialog" title="确认发货" width="1100px">
      <div class="contentDiv">
        <div class="leftContent contentItem">
          <div>
            <span>请选择要发货的商品,</span><span style="color:	#00BFFF"> 共{{this.deliverGoodsData.length}}个,</span><span style="color:	#FF0000"> 已选中{{this.multipleChoice.length}}个</span>
          </div>
          <el-table
            :data="deliverGoodsData"
            tooltip-effect="dark"
            style="width: 100%"
            :height="tableHeight"
            @selection-change="handleSelectionChange">
            <el-table-column  min-width="40">
              <template slot-scope="{ row }">
                <img :src="row.image" class="deliver-img" />
              </template>
            </el-table-column>
            <el-table-column  min-width="90">
              <div slot-scope="{ row }" class="deliver-detail">
                <p>{{row.name}}</p>
                <p v-if="row.spec_json">{{row.spec_json[0].spec_value}}</p>
              </div>
            </el-table-column>
            <el-table-column type="selection" width="60" class="selection"/>
          </el-table>
        </div>
        <div class="rightContent contentItem">
          <el-form :model="goodSendForm" :rules="goodSendFormRules" ref="goodSendFormRef" label-width="100px">
            <el-form-item  label="发货方式：" prop="shipping_type">
              <el-radio-group v-model="goodSendForm.shipping_type">
                <el-radio label="GLOBAL">快递发货<span class="bottomred">（客户要求）</span></el-radio>
                <el-radio label="LOCAL" disabled>同城配送</el-radio>
                <el-radio label="SELF" disabled>客户自提</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item v-if="goodSendForm.shipping_type!=='SELF'" label="快递公司" prop="logi_id">
              <el-select v-model="goodSendForm.logi_id" class="select-type" clearable>
                <el-option
                  v-for="option in s_logi_option"
                  :label="option.name"
                  :value="option.id"
                  :key="option.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="goodSendForm.shipping_type!=='SELF'" label="快递单号" prop="ship_no">
              <el-input v-model="goodSendForm.ship_no" placeholder="请输入快递单号"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer footerBtn">
            <el-button type="primary" @click="deliverGoodsSubmit()">确 定 发 货</el-button>
            <el-button @click="deliverGoodsDialog = false">取 消</el-button>
          </div>
        </div>
      </div>
    </el-dialog>

    <!-- 批量取消订单 -->
    <el-dialog :visible.sync="cancelOrdertDialog" title="批量取消订单" width="800px">
      <el-form :model="cancelOrderForm" :rules="pushRules" ref="cancelOrderForm" label-width="100px">
        <el-form-item label="订单编号：" prop="order_sn_string" required>
          <el-input type="textarea"  v-model="cancelOrderForm.order_sn_string" placeholder="请输入订单编号，多个用户用逗号“，”分隔" clearable></el-input>
        </el-form-item>
        <el-form-item label="取消理由：" prop="cancel_reason">
          <el-input type="textarea"  v-model="cancelOrderForm.cancel_reason" clearable></el-input>
        </el-form-item>
        <el-form-item label="备注：" prop="remark">
          <el-input type="textarea"  v-model="cancelOrderForm.remark" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogPushShow = false">取 消</el-button>
        <el-button type="primary" @click="submitpushForm('cancelOrderForm')" :loading="btnLoading">确认推送</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import * as API_order from "@/api/order";
import { Foundation } from "~/ui-utils";
import { getDict } from '@/common/filter-show';
// let multipleSelection = []

export default {
  name: "orderList",
  data() {
    return {
      // 列表loading状态
      loading: false,
      // 批量取消订单loading状态
      btnLoading: false,
      // 导入excel的弹框
      importDialog: false,
      // 批量取消订单
      cancelOrdertDialog: false,
      // 导入excel的弹框
      deliverGoodsDialog: false,
      /** 取消订单表单 */
      cancelOrderForm: {
        order_sn_string: '',
        cancel_reason: '',
        remark: ''
      },
      pushRules: {
        order_sn_string: [
          { required: true, message: '请输入订单编号，多个用户用逗号“，”分隔', trigger: 'blur' }
        ],
        cancel_reason: [
          { required: false, message: '请输入取消理由', trigger: 'blur' }
        ],
        remark: [
          { required: false, message: '请输入备注', trigger: 'blur' }
        ]
      },
      // 导入的form表单
      importForm: {
        uploadFile: undefined
      },
      importFormRules: {
        uploadFile: [
          {
            required: true,
            message: '上传文件不能为空',
            trigger: 'blur'
          }
        ]
      },
      // 列表参数
      params: {
        page_no: 1,
        page_size: 10
      },
      // 列表数据
      tableData: "",
      // 展示确认发货的数据
      deliverGoodsData: [],
      // 发货确认表格高度
      tableHeight: 400,
      // 确认发货多选
      multipleChoice: [],
      // 添加表单验证
      goodSendFormRules: {
        shipping_type: [
          { required: true, message: '请选择发货方式', trigger: 'blur' }
        ],
        logi_id: [
          { required: true, message: '请选择快递公司', trigger: 'blur' }
        ],
        ship_no: [
          { required: true, message: '请输入快递单号', trigger: 'blur' }
        ]
      },
      // 物流公司名称下拉框 类似于option
      s_logi_option: [],
      // 批量发货数据表单
      goodSendForm: {
        shipping_type: '',
        logi_id: '',
        ship_no: ''
      },
      delivery_no: '', // 快递单号
      selectedDatas: null,
      tableIsIndeterminate: null,
      tableCheckAll: null,
      multipleSelection: null,

      /** 订单sn */
      sn: '',
      seller_id: '',
      logi_name: '',
      logi_id: '',
      _hasDictArray: [],

      // 高级搜索数据
      advancedForm: {},
      options: []
    };
  },
  filters: {
    paymentTypeFilter(val) {
      return val === "ONLINE" ? "在线支付" : "货到付款";
    }
  },
  mounted() {
    // 获取格式化字典数据
    this.getDictData('shetuan_seller_id');
    this.GET_OrderList();
  },
  // activated() {
  //   this.GET_OrderList();
  // },
  methods: {
    /** 分页大小发生改变 */
    handlePageSizeChange(size) {
      this.params.page_size = size;
      this.GET_OrderList();
    },

    /** 分页页数发生改变 */
    handlePageCurrentChange(page) {
      this.params.page_no = page;
      this.GET_OrderList();
    },

    // 获取字典
    getDictData (dictType) { // 储存已获取的字典
      let _params = {
        type: dictType
      };
      getDict(_params).then(res => {
        let _data = res.data;
        if (_data.length > 0) {
          this._hasDictArray = _data;
        }
      });
    },
    
    /** 获取选中项*/
    selectionChange(val) {
      this.sn = val[0] ? val[0].sn : '';
      this.seller_id = val[0] ? val[0].seller_id : '';
      const _count = val.length;
      const _tableLength = this.tableData.length;
      this.selectedDatas = val;
      this.tableIsIndeterminate = _count > 0 && _count < _tableLength;
      this.tableCheckAll = _count === _tableLength;
      if (_count === 0) {
        this.tableCheckAll = false;
      } else if (_count === _tableLength) {
        this.tableCheckAll = true;
      }
      this.multipleSelection = val;
    },
    openDeliverGoodsialog() {
      if (this.multipleSelection.length > 1) {
        this.$message.warning('发货只能选择一个订单！');
        return false;
      }
      this.deliveryOrder();
      this.getOrdersShipDetail();
    },
    /**
      * @date 2020/12/03
      * @author luocheng
      * @description {批量发货弹框触发，以及获取物流公司的下拉列表 这里因为不能同时获取到}
    */
    deliveryOrder() {
      if (!this.multipleSelection.length) {
        this.$message.warning('请选择商品！');
        return;
      }
      // 部分表单数据清空
      this.goodSendForm.logi_id = '';
      this.goodSendForm.ship_no = '';
      this.s_logi_option = [];
      for (let item of this.multipleSelection) {
        let currentSallerId = this._hasDictArray.find((findItem) => {
          return item.seller_id.toString() === findItem.value;
        });
        if (currentSallerId) {
          this.$message.warning('只能对商城订单进行发货操作！');
          return;
        }
        if (item.order_status !== 'PAID_OFF') {
          this.$message.warning('选中的订单中存在非待发货的订单，不能发货！');
          return;
        }
        // if (item.service_status !== 'NOT_APPLY') {
        //   this.$message.warning('选中的订单中存在售后中的订单，不能发货！');
        //   return;
        // }
      }
      API_order.queryExpressList(this.seller_id).then(response => {
        if (!response.length) {
          this.$message.error('没有物流公司，请先去设置')
        }
        response.forEach(item => {
          let params = {
            name: item.logistics_company_do.name,
            id: item.logistics_company_do.id
          }
          this.s_logi_option.push(params);
        })
        if (this.s_logi_option.length && this.deliverGoodsData.length) {
          this.deliverGoodsDialog = true;
        }
      }).catch()
      this.goodSendForm.shipping_type = "GLOBAL";
      this.goodDialogVisible = true;
    },
    /** -------- 订单列表的详情 --------- */
    /**
      * @date 2020/12/02
      * @author luocheng
      * @description { 订单列表的详情信息, 需要做判断才能调用接口 }
    */
    getOrdersShipDetail() {
      API_order.getOrdersShipDetail(this.sn).then(response => {
        this.deliverGoodsData = response;
        for (let item of this.deliverGoodsData) {
          item.spec_json = JSON.parse(item.spec_json)
        }
        if (this.s_logi_option.length && this.deliverGoodsData.length>0) {
          this.deliverGoodsDialog = true;
        }
        this.deliverGoodsData = this.deliverGoodsData.filter(key => {
          return key.ship_status !== 'SHIP_YES';
        })
        this.deliverGoodsData = this.deliverGoodsData.filter(key => {
          return key.service_status === 'NOT_APPLY';
        })
      }).catch(error => {
        console.log(error)
      })
    },
    /** -------- 批量取消订单 --------- */
    /**
      * @date 2021/04/17
      * @author luocheng
      * @description { 批量取消订单 }
    */
    submitpushForm() {
      this.btnLoading = true
      API_order.sellerRefund(this.cancelOrderForm).then(response => {
        // this.deliverGoodsData = response;
        console.log(response)
        this.btnLoading = false
      }).catch(error => {
        console.log(error)
        this.btnLoading = false
      })
    },
    /**
      * @date 2020/12/02
      * @author luocheng
      * @description { 确认发货按钮事件 }
    */
    deliverGoodsSubmit() {
      if (!this.multipleChoice.length) {
        this.$message({
          type: 'error',
          message: '确认发货最少选择一件商品!'
        })
        return
      }
      let selectionData = [];
      for (let item of this.multipleChoice) {
        selectionData.push(item.product_id)
      }
      
      for (let item of this.multipleSelection) {
        if (item.order_status !== 'PAID_OFF'  || item.service_status === 'APPLY') {
          this.$message.warning('选中的订单中存在售后中或非待发货的订单，不能发货！');
          return;
        }
      }

      this.$refs['goodSendFormRef'].validate((valid) => {
        if (valid) {
          let logiData = this.s_logi_option.find((item) => {
            return item.id === this.goodSendForm.logi_id;
          });

          // 部分表单数据清空
          this.delivery_no = this.goodSendForm.ship_no;
          this.goodSendForm.logi_id = '';
          this.goodSendForm.ship_no = '';

          let params = {
            'sku_ids': selectionData,
            'order_sn': this.sn,
            'delivery_no': this.delivery_no,
            'logi_id': logiData.id,
            'logi_name': logiData.name
          }
          API_order.getOrdersSplitDelivery(params).then(response => {
            if (response === "SUCCESS") {
              this.$message({
                type: 'success',
                message: '发货成功'
              })
              this.getOrdersShipDetail();
              if (this.deliverGoodsData.length < 1) {
                this.deliverGoodsDialog = false;
              }
            } else {
              this.$message({
                type: 'error',
                message: '分批发货失败, 请联系管理员!'
              })
              this.deliverGoodsDialog = false;
            }
          })
        }
      })
    },
    /**
      * @date 2020/12/02
      * @author luocheng
      * @description { 确认发货多选 }
    */
    handleSelectionChange(item) {
      this.multipleChoice = item;
    },

    /** 搜索事件触发 */
    searchEvent(data) {
      delete this.params.start_time;
      delete this.params.end_time;
      if (this.advancedForm.order_time_range) {
        this.params.start_time = this.advancedForm.order_time_range[0];
        this.params.end_time = this.advancedForm.order_time_range[1];
      }
      this.params = {
        ...this.params,
        ...this.advancedForm,
        order_sn: data
      };
      delete this.params.order_time_range;
      this.params.page_no = 1;
      Object.keys(this.params).forEach((_key) => {
        if (this.params[_key] === "") {
          delete this.params[_key];
        }
      });
      this.GET_OrderList();
    },

    /** 高级搜索事件触发 */
    advancedSearchEvent() {
      this.params = {
        ...this.params,
        ...this.advancedForm
      };
      delete this.params.start_time;
      delete this.params.end_time;
      if (this.advancedForm.order_time_range) {
        this.params.start_time = this.advancedForm.order_time_range[0];
        this.params.end_time = this.advancedForm.order_time_range[1];
      }
      delete this.params.order_sn;
      delete this.params.order_time_range;
      this.params.page_no = 1;
      Object.keys(this.params).forEach((_key) => {
        if (this.params[_key] === "") {
          delete this.params[_key];
        }
      });
      this.GET_OrderList();
    },

    /** 查看、操作订单 */
    handleOperateOrder(index, row) {
      this.$router.push({
        name: "orderDetail",
        params: {
          sn: row.sn,
          callback: this.GET_OrderList
        }
      });
    },
    /**
      * @date 2020/12/03
      * @author luocheng
      * @description { 导入excel }
    */
    importExcel() {
      this.importDialog = true;
    },
    cancelOrder() {
      this.cancelOrdertDialog = true;
    },
    /**
      * @date 2020/12/03
      * @author luocheng
      * @description { 切换上传的文件 }
    */
    onUploadChange(file, fileList) {
      this.importForm.uploadFile = file
    },
    /**
      * @date 2020/12/03
      * @author luocheng
      * @description { 覆盖原有上传文件的方法 }
    */
    excelLoadShow(content) {
      this.files = content.file;
    },
    submitFileForm() {
      let uploadFile = new FormData();
      uploadFile.append('uploadFile', this.files);
      if (!this.files) {
        this.$message({
          type: 'warning',
          message: '请选择上传文件'
        })
        return 
      }
      API_order.shipOrderImport(uploadFile).then(response => {
        if (response.code === 602) {
          this.$message({ 
            type: 'warning',
            message: response.message
          })
        } else {
          if (response.size !== 0) {
            this.$confirm('当前导入商品信息的保存出错了,是否下载查看')
              .then(_ => {
                // 处理返回的文件流
                let blob = new Blob([response], {
                  type: 'application/vnd.ms-excel;charset=utf-8'
                });
                let date = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate();
                const fileName = date + name + '保存出错的社团商品明细.xlsx';
                this.$refs.upload.clearFiles();
                this.importForm.uploadFile = undefined;
                this.importDialog = false;
                if ('download' in document.createElement('a')) {
                  // 非IE下载
                  const elink = document.createElement('a');
                  elink.download = fileName;
                  elink.style.display = 'none';
                  elink.href = URL.createObjectURL(blob);
                  document.body.appendChild(elink);
                  elink.click();
                  URL.revokeObjectURL(elink.href); // 释放URL 对象
                  document.body.removeChild(elink);
                }
              }).catch(_ => {
                this.$message({
                  type: 'warning',
                  message: '操作已取消'
                })
                this.$refs.upload.clearFiles();
                this.importForm.uploadFile = undefined;
                this.importDialog = false;
              });
          } else {
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.$refs.upload.clearFiles();
            this.importForm.uploadFile = undefined;
            this.importDialog = false;
            this.GET_ShetuanGoodsList();
          }
        }
      })
    },
    handleCancel() {
      this.importDialog = false;
      this.files = null;
      this.$refs.upload.clearFiles();
    },

    /** 导出订单 */
    handleExportOrders() {
      if (this.params.start_time && this.params.end_time) {
        this.params.start_time = parseInt(this.params.start_time / 1000);
        this.params.end_time = parseInt(this.params.end_time / 1000);
      }
      API_order.exportOrders(this.params).then((response) => {
        const json = {
          sheet_name: "订单列表",
          sheet_values: response.map((item) => ({
            订单编号: item.sn,
            交易单号: item.trade_sn,
            下单时间: Foundation.unixToDate(item.create_time),
            所属店铺: item.seller_name,
            团长姓名: item.lv1_member_nick_name,
            团长电话: item.lv1_member_mobile,
            合作模式: item.cooperation_mode_label,
            结算方式: item.settlement_method_label,
            下单会员: item.member_name,
            订单总额: Foundation.formatPrice(item.order_amount),
            订单运费: Foundation.formatPrice(item.shipping_amount),
            优惠金额: Foundation.formatPrice(item.discount_price),
            订单状态: item.order_status_text,
            付款状态: item.pay_status_text,
            发货状态: item.ship_status_text,
            付款类型: item.payment_type === "ONLINE" ? "在线支付" : "货到付款",
            付款方式: item.payment_method_name,
            付款时间: Foundation.unixToDate(item.payment_time),
            付款金额: Foundation.formatPrice(item.pay_money),
            收货人: item.ship_name,
            收货人联系方式: item.ship_mobile,
            收货地址:
              item.ship_province +
              "" +
              item.ship_city +
              "" +
              item.ship_county +
              "" +
              item.ship_town +
              "-" +
              item.ship_addr,
            物流公司: item.logi_name,
            快递单号: item.ship_no,
            订单发货时间: Foundation.unixToDate(item.ship_time),
            订单收货时间: Foundation.unixToDate(item.signing_time),
            订单完成时间: Foundation.unixToDate(item.complete_time),
            订单来源: item.client_type,
            是否需要发票: item.need_receipt === 1 ? "需要" : "不需要",
            订单取消原因: item.cancel_reason,
            买家备注: item.remark
          }))
        };
        this.MixinExportJosnToExcel(json, "订单列表");
      });
    },

    /** 导出订单 */
    handleExportOrderItems() {
      if (this.params.start_time && this.params.end_time) {
        this.params.start_time = parseInt(this.params.start_time / 1000);
        this.params.end_time = parseInt(this.params.end_time / 1000);
      }
      API_order.exportOrderItems(this.params).then((response) => {
        // 处理返回的文件流
        let blob = new Blob([response], {
          type: "application/vnd.ms-excel;charset=utf-8"
        });
        let date =
          new Date().getFullYear() +
          "" +
          (new Date().getMonth() + 1) +
          "" +
          new Date().getDate();
        const fileName = date + name + "订单明细导出.xlsx";
        if ("download" in document.createElement("a")) {
          // 非IE下载
          const elink = document.createElement("a");
          elink.download = fileName;
          elink.style.display = "none";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        } else {
          // IE10+下载
          navigator.msSaveBlob(blob, fileName);
        }
      });
    },

    /** 获取订单列表 */
    GET_OrderList() {
      this.loading = true;
      const params = this.MixinClone(this.params);
      if (params.start_time && params.end_time) {
        params.start_time = parseInt(params.start_time / 1000);
        params.end_time = parseInt(params.end_time / 1000);
      }
      if (params.seller_id === 0) delete params.seller_id;
      API_order.getOrderList(params)
        .then((response) => {
          this.loading = false;
          this.tableData = response;
        })
        .catch(() => {
          this.loading = false;
        });
    }
  }
};
</script>

<style type="text/scss" lang="scss" scoped>
/deep/ .el-table td:not(.is-left) {
  text-align: center;
}

.inner-toolbar {
  display: flex;
  width: 100%;
  justify-content: space-between;
  padding: 0 20px;
}

.goods-image {
  width: 50px;
  height: 50px;
}
.exprot-tip {
  margin-left: 5px;
  color: red;
  font-size: 12px;
}
//设置远程搜索(关联用户)左右对齐
.mobile {
  float: right;
}
.el-date-editor--datetimerange.el-input,
.el-date-editor--datetimerange.el-input__inner {
  width: 100%;
}
.contentDiv{
  display: flex;
  flex-flow: row nowrap;
  .contentItem{
    width: 50%;
    height: 100%;
    padding: 0 10px;
  }
  .leftContent{
    border-right: #606266 solid 1px;
  }
  .rightContent .footerBtn{
    width: 35%;
    margin-left:100px;
  }
}
.deliver-img {
  width: 100px;
  height: 100px;
}
.deliver-detail {
  text-align: left;
}
.deliver-detail > p:nth-child(1) {
  font-weight: bold;
}
/deep/ .en-search > div:nth-child(1){
  width: 90%!important;
}
.choosedPromos{
  color: rgb(236, 18, 18);
}
</style>
